// CJS import
const { default: SignJWT } = require("jose/jwt/sign");
const { default: parseJwk } = require("jose/jwk/parse");
const { default: generateSecret } = require("jose/util/generate_secret");
const { default: generateKeyPair } = require("jose/util/generate_key_pair");

const fromKeyLike = require("jose/jwk/from_key_like").default;
// CJS import
const jwtEncrypt = require("jose/jwt/encrypt").default;
const jwtDecrypt = require("jose/jwt/decrypt").default;

(async () => {
  const userSecretKey = Uint8Array.from([
    206,
    203,
    53,
    165,
    235,
    214,
    153,
    188,
    248,
    225,
    1,
    132,
    105,
    204,
    75,
    42,
    186,
    185,
    24,
    223,
    136,
    66,
    116,
    59,
    183,
    155,
    52,
    52,
    101,
    167,
    201,
    86,
  ]);

  const jwt = await new jwtEncrypt({ uid: 123 })
    .setProtectedHeader({ alg: "dir", enc: "A256GCM" })
    .setIssuedAt()
    .setAudience("uyh:app")
    .setExpirationTime("2h")
    .encrypt(userSecretKey);

  const { payload, protectedHeader } = await jwtDecrypt(jwt, userSecretKey);
  console.log(protectedHeader);
  console.log(payload);
})();
